package com.bwie.home.backstage.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.home.backstage.entity.CommunityEntity;
import com.bwie.home.backstage.service.CommunityService;
import com.bwie.home.common.utils.PageUtils;
import com.bwie.home.common.utils.R;



/**
 * 
 *
 * @author sy
 * @email sunlightcs@gmail.com
 * @date 2021-09-10 09:46:41
 */
@RestController
@RequestMapping("backstage/community")
public class CommunityController {
    @Autowired
    private CommunityService communityService;

    /**
     * 根据省市县、小区名称、状态查询小区列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,@RequestBody CommunityEntity community){
        PageUtils page = communityService.queryPage(params,community);

        return R.ok().put("page", page);
    }


    /**
     * 获取指定小区ID的信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		CommunityEntity community = communityService.getById(id);

        return R.ok().put("community", community);
    }

    /**
     * 添加小区列表
     */
    @RequestMapping("/save")
    public R save(@RequestBody CommunityEntity community){
        community.setCreatetime(new Date());
		communityService.save(community);

        return R.ok();
    }

    /**
     * 修改小区列表
     */
    @RequestMapping("/update")
    public R update(@RequestBody CommunityEntity community){
		communityService.updateById(community);

        return R.ok();
    }

    /**
     * 批量删除指定小区ID的信息
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		communityService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
